package com.itmk.web.home;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itmk.utils.ResultUtils;
import com.itmk.utils.ResultVo;
import com.itmk.web.goods.entity.Goods;
import com.itmk.web.goods.service.GoodsService;
import com.itmk.web.wx_user.service.WxUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/api/home")
//代表是个控制器
@RestController
public class HomeController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private WxUserService wxUserService;

    //统计总数
    @GetMapping("/getTotal")
    public ResultVo getTotal(){
        TotalVo vo = new TotalVo();
        //查询失物总数
        //以下是查询条件的编写
        QueryWrapper<Goods> lostquery = new QueryWrapper<>();
        lostquery.lambda().eq(Goods::getType,"0");
        int lostcount = goodsService.count(lostquery);
        vo.setLostCount(lostcount);
        //查询招领总数
        QueryWrapper<Goods> claimquery = new QueryWrapper<>();
        claimquery.lambda().eq(Goods::getType,"1");
        int findcount = goodsService.count(claimquery);
        vo.setClaimCount(findcount);
        //查询微信小程序用户总数
        int count = wxUserService.count();
        vo.setUserCount(count);
        return ResultUtils.success("查询成功",vo);
    }
}
